package com.tiny.work.btrace.Counter;

/* BTrace Script Template */
import com.sun.btrace.annotations.*;

import java.lang.reflect.Field;

import static com.sun.btrace.BTraceUtils.Reflective.field;
import static com.sun.btrace.BTraceUtils.Reflective.get;
import static com.sun.btrace.BTraceUtils.*;
@BTrace
public class TraceTotalCounter {
    /* 定时获取Counter类的属性值totalCount。  */
    private static Integer totalCount = 0;
    @OnMethod(
            clazz = "com.sample.test.Counter",
            method = "add",
            location = @Location(Kind.RETURN)
    )
    public static void traceExecute(@Self Object counter){
        Field field = field("com.sample.test.Counter", "totalCount");
        totalCount = (Integer) get(field, counter);

    }
    @OnTimer(1000)
    public static void print(){
        println("====== ");
        println(strcat("totalCount: ",str(totalCount)));
    }
}